﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using QLBH.Controllers;
using QLBH.Models;

namespace QLBH.Modules
{
    public partial class ucGood : UserControl
    {
        private GoodController controller;
        public ucGood()
        {
            InitializeComponent();
            
            controller = new GoodController(this);
        }

        private void ucGood_Load(object sender, EventArgs e)
        {
            controller.LoadData();
        }
        public void DisplayData(List<GoodModel> model)
        {
            dgvGood.AutoGenerateColumns = false;
            dgvGood.DataSource = model;
        }
        private void btnAdd_Click(object sender, EventArgs e)
        {
            controller.Add();
        }

        private void btnReset_Click(object sender, EventArgs e)
        {
            controller.LoadData();
        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            controller.Delete();
        }

        private void btnEdit_Click(object sender, EventArgs e)
        {
            controller.Edit();
        }
        public GoodModel getCurrentSelectedItem()
        {
            if (dgvGood.SelectedRows.Count > 0)
            {
                return dgvGood.SelectedRows[0].DataBoundItem as GoodModel;
            }
            return null;
        }
    }
}
